<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
'列表
id=request.QueryString("id")
search=request.QueryString("search")
if search="搜索" then
	key=request.QueryString("key")
	mark=request.QueryString("mark")
	if key<>"" then
		sqlsearch=" and (id like '%"&key&"%' or title like '%"&key&"%')"
	end if
end if


'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by id desc ) as sortid,* From brand) as TempTable where 1=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" [id],[title],sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<script language="javascript" type="text/javascript" src="../js/bd.js"></script>
</head>

<body>
<div class="main">
  <div class="main-title">商品品牌管理: <a href="?id=<%=id%>&a=y">添加</a> &nbsp;&nbsp;
    <%
  if parent_cid<>"" then response.Write "<a href='?cid="&parent_cid&"'>上一级</a>"
  if fid<>"" then response.Write "<a href='?id="&fid&"'>上一级</a>"
  %></div>
  <div class="main-content">
  
  
  <%if request.QueryString("a")="y" then%>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form name="theForm" id="demo" method="post" onSubmit="return Validator.Validate(this,3)">
  <tr>
    <td width="10%" bgcolor="#FFFFFF">名称</td>
    <td width="90%" colspan="6" bgcolor="#FFFFFF"><input name="title" type="text" class="input" id="title" maxlength="50" dataType="LimitB" min="1" max="50" msg="分类名称[1,50]字符以内" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td colspan="6" bgcolor="#FFFFFF">
      <input name="fid" type="hidden" id="fid" value="<%=id%>" />
      <input type="submit" name="button" id="button" value="添加" onClick="Validator.Validate(document.getElementById('demo'),3)" />
      <a href="javascript:;" onClick="javascript:history.back(-1);">返回</a>
      
      </td>
  </tr>
    </form>
   </table>
   <%end if%>
  
  <%if request.QueryString("e")="y" then%>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <%
  set rsm=server.CreateObject("adodb.recordset")
  sql="select * from brand where id="&request.QueryString("edit")&""
  rsm.open sql,conn,1,3
  if not rsm.eof then
  %>
  <form name="theForm" id="demo" method="post" onSubmit="return Validator.Validate(this,3)">
  <tr>
    <td width="10%" bgcolor="#FFFFFF">名称</td>
    <td width="90%" colspan="6" bgcolor="#FFFFFF"><input name="title" type="text" class="input" id="title" maxlength="50" value="<%=rsm("title")%>" dataType="LimitB" min="1" max="50" msg="分类名称[1,50]字符以内" /></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF">&nbsp;</td>
    <td colspan="6" bgcolor="#FFFFFF">
      <input name="edit" type="hidden" value="<%=request.QueryString("edit")%>" />
      <input type="submit" name="button" id="button" value="保存" onClick="Validator.Validate(document.getElementById('demo'),3)" />
      <a href="javascript:;" onClick="javascript:history.back(-1);">返回</a>
      
      </td>
  </tr>
    </form>
    <%
	rsm.close
	set rsm=nothing
	end if
	%>
   </table>
  <%end if%>
  
  
  
  
  
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center" bgcolor="#FFFFFF">
    <form name="form" method="get" action="">
    <input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td width="6%" align="center" bgcolor="#FFFFFF"><strong>选择</strong></td>
    <td width="38%" align="center" bgcolor="#FFFFFF"><strong>id</strong></td>
    <td width="28%" align="center" bgcolor="#FFFFFF"><strong>名称</strong></td>
    <td width="28%" align="center" bgcolor="#FFFFFF"><strong>操作</strong></td>
    </tr>
    <%do while not Rs.eof%>
  <tr>
    <td align="center"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("id")%>" /></td>
    <td align="center"><%=rs("id")%></td>
    <td align="center"><%=rs("title")%></td>
    <td align="center"><a href="?id=<%=id%>&edit=<%=rs("id")%>&e=y">修改</a></td>
    </tr>
    <%
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="4" align="center" bgcolor="#FFFFFF" class="page">
      <input type="submit" name="button" id="button" value="删除" />
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="4" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
   
        <%
		pageurl=siteurl&"?"&"key="&key&"&mark="&mark&"&cid="&cid&"&id="&id&"&search="&search&"&"
		if CurrentPage<=1 then
		pageview="<a> < </a>"
		else
		pageview="<a href='"&pageurl&"page="&CurrentPage-1&"'> < </a>"
		end if
		if CurrentPage>=7 then
		pageview=pageview+"<a href='"&pageurl&"page=1'>1</a><a>...</a>"
		end if
		for tp = -4 to 4
		if Pager_PageCount>=tp+CurrentPage and tp+CurrentPage=>1  then 
		if trim(tp+CurrentPage)=CurrentPage or tp=0 then
		pageview=pageview+"<a class='cur_page'>"&tp+CurrentPage&"</a>"
		else
		pageview=pageview+"<a"&pagecss&" href='"&pageurl&"page="&tp+CurrentPage&"'>"&tp+CurrentPage&"</a>"
		end if
		end if
		next
		if Pager_PageCount>tp+CurrentPage then pageview=pageview+"<a>...</a>"
		if Pager_PageCount<CurrentPage+1 then
		pageview=pageview+"<a> > </a>"
		else
		pageview=pageview+"<a href='"&pageurl&"page="&CurrentPage+1&"'> > </a>"
		end if
		response.Write pageview
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="cid" value="<%=cid%>" />
        <input type="hidden" name="id" value="<%=id%>" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="mark" value="<%=mark%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
      </td>
    </tr>
  </table>
</div>
</div>
</body>
</html>
<%
if request.Form("button")="添加" then

	title=request.Form("title")
	
	if title="" then
	response.write"<script>alert('名称不能为空');</script>"
	response.write"<script>window.history.back(-1);</script>"
	response.end
	end if

	set rsu=server.createobject("adodb.recordset")
	sql="select * from brand"
	rsu.open sql,conn,1,3
	rsu.addnew
	rsu("title")=title
	rsu.update
	response.write"<script language=JavaScript>{window.alert('添加成功！');window.location.href='brand.asp?id="&id&"&page="&request("page")&"';}</script>"
	rsu.close
	set rsu=nothing
	
elseif request.Form("button")="保存" then

	edit=request.Form("edit")
	title=request.Form("title")
	
	if title="" or edit="" then
	response.write"<script>alert('名称不能为空');</script>"
	response.write"<script>window.history.back(-1);</script>"
	response.end
	end if

	set rsu=server.createobject("adodb.recordset")
	sql="select * from brand where id="&edit&""
	rsu.open sql,conn,1,3
	rsu("title")=title
	rsu.update
	response.write"<script language=JavaScript>{window.alert('保存成功！');window.location.href='brand.asp?id="&id&"&page="&request("page")&"';}</script>"
	rsu.close
	set rsu=nothing
end if





checkbox=request.Form("checkbox")
if checkbox<>"" then	
	if request.Form("button")="删除" then
		conn.execute("delete from brand where id in("&checkbox&")")
	end if
	response.Redirect "type.asp?id="&request.QueryString("id")&"&page="&request.QueryString("page")&""
end if
%>